from openpyxl import Workbook
from openpyxl.chart import (
    AreaChart3D,  # 3D区域图
    Reference,  # 引用
    Series,  # 系列
)

# 创建工作簿
wb = Workbook()
# 创建工作表
ws = wb.active

# 数据
rows = [
    ['Number', 'Batch 1', 'Batch 2'],
    [2, 30, 40],
    [3, 25, 40],
    [4, 30, 50],
    [5, 10, 30],
    [6, 5, 25],
    [7, 10, 50],
]

# 向工作表追加数据
for row in rows:
    ws.append(row)

# 创建3D区域图
chart = AreaChart3D()
# 标题
chart.title = "3D区域图"
# 样式
chart.style = 13
# x轴标题
chart.x_axis.title = 'x轴'
# y轴标题
chart.y_axis.title = 'y轴'
# 不显示图例
chart.legend = None
# 从工作表提取第1列
cats = Reference(ws, min_col=1, min_row=1, max_row=7)
# 从工作表提取第2列
data = Reference(ws, min_col=2, min_row=1, max_col=3, max_row=7)
# 将数据添加到图表
chart.add_data(data, titles_from_data=True)
# 将分类添加到图表
chart.set_categories(cats)

# 将图标添加到工作表中的指定单元格
ws.add_chart(chart, "A10")

# 保存Excel
wb.save("area3D.xlsx")
